package edu.hubu.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import net.moon.jpa.model.BaseEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author moonlan
 * @date 2020/10/18 下午4:41
 */

@Entity
@Table(name = "course_type")
//逻辑删除注解，删除sql变成了update
@SQLDelete(sql = "update course_type set course_type_is_deleted = true where course_type_id = ?")
//where条件带上了逻辑删除条件
@Where(clause = "course_type_is_deleted = false")
@ApiModel("课程类型")
@JsonIgnoreProperties(value={"hibernateLazyInitializer", "handler", "fieldHandler"})
public class CourseType extends BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeId")
    @GenericGenerator(name = "snowflakeId", strategy = "edu.hubu.commons.SnowflakeId",
                      parameters = {@org.hibernate.annotations.Parameter(name = "prefix", value = "COURSE-TYPE")})
    @Column(name = "course_type_id")
    @ApiModelProperty(value = "courListype的id", position = 1)
    private String courseTypeId;

    @Column(name = "course_type_name")
    @ApiModelProperty(value = "课程类型名", position = 2)
    private String courseTypeName;

    @Column(name = "course_type_is_forbidden")
    @ApiModelProperty(value = "课程类型是否被禁用", position = 3)
    private boolean courseTypeIsForbidden = false;

    @Column(name = "course_type_is_deleted")
    @ApiModelProperty(value = "课程类型是否被删除", position = 4)
    private boolean courseTypeIsDeleted = false;

    @OneToMany(mappedBy = "courseType", fetch = FetchType.LAZY)
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    private List<TeacherCourse> teacherCourses = new ArrayList<>();

    @OneToMany(mappedBy = "courseType", fetch = FetchType.LAZY)
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    private List<StudentCourse> studentCourses = new ArrayList<>();

    public CourseType(String courseTypeId, String courseTypeName, boolean courseTypeIsForbidden, boolean courseTypeIsDeleted, List<TeacherCourse> teacherCourses, List<StudentCourse> studentCourses) {
        this.courseTypeId = courseTypeId;
        this.courseTypeName = courseTypeName;
        this.courseTypeIsForbidden = courseTypeIsForbidden;
        this.courseTypeIsDeleted = courseTypeIsDeleted;
        this.teacherCourses = teacherCourses;
        this.studentCourses = studentCourses;
    }

    public CourseType() {
    }

    public static CourseTypeBuilder builder() {
        return new CourseTypeBuilder();
    }

    public String getCourseTypeId() {
        return this.courseTypeId;
    }

    public String getCourseTypeName() {
        return this.courseTypeName;
    }

    public boolean isCourseTypeIsForbidden() {
        return this.courseTypeIsForbidden;
    }

    public boolean isCourseTypeIsDeleted() {
        return this.courseTypeIsDeleted;
    }

    public List<TeacherCourse> getTeacherCourses() {
        return this.teacherCourses;
    }

    public List<StudentCourse> getStudentCourses() {
        return this.studentCourses;
    }

    public void setCourseTypeId(String courseTypeId) {
        this.courseTypeId = courseTypeId;
    }

    public void setCourseTypeName(String courseTypeName) {
        this.courseTypeName = courseTypeName;
    }

    public void setCourseTypeIsForbidden(boolean courseTypeIsForbidden) {
        this.courseTypeIsForbidden = courseTypeIsForbidden;
    }

    public void setCourseTypeIsDeleted(boolean courseTypeIsDeleted) {
        this.courseTypeIsDeleted = courseTypeIsDeleted;
    }

    public void setTeacherCourses(List<TeacherCourse> teacherCourses) {
        this.teacherCourses = teacherCourses;
    }

    public void setStudentCourses(List<StudentCourse> studentCourses) {
        this.studentCourses = studentCourses;
    }

    public static class CourseTypeBuilder {
        private String courseTypeId;
        private String courseTypeName;
        private boolean courseTypeIsForbidden;
        private boolean courseTypeIsDeleted;
        private List<TeacherCourse> teacherCourses;
        private List<StudentCourse> studentCourses;

        CourseTypeBuilder() {
        }

        public CourseTypeBuilder courseTypeId(String courseTypeId) {
            this.courseTypeId = courseTypeId;
            return this;
        }

        public CourseTypeBuilder courseTypeName(String courseTypeName) {
            this.courseTypeName = courseTypeName;
            return this;
        }

        public CourseTypeBuilder courseTypeIsForbidden(boolean courseTypeIsForbidden) {
            this.courseTypeIsForbidden = courseTypeIsForbidden;
            return this;
        }

        public CourseTypeBuilder courseTypeIsDeleted(boolean courseTypeIsDeleted) {
            this.courseTypeIsDeleted = courseTypeIsDeleted;
            return this;
        }

        public CourseTypeBuilder teacherCourses(List<TeacherCourse> teacherCourses) {
            this.teacherCourses = teacherCourses;
            return this;
        }

        public CourseTypeBuilder studentCourses(List<StudentCourse> studentCourses) {
            this.studentCourses = studentCourses;
            return this;
        }

        public CourseType build() {
            return new CourseType(courseTypeId, courseTypeName, courseTypeIsForbidden, courseTypeIsDeleted, teacherCourses, studentCourses);
        }

        public String toString() {
            return "CourseType.CourseTypeBuilder(courseTypeId=" + this.courseTypeId + ", courseTypeName=" + this.courseTypeName + ", courseTypeIsForbidden=" + this.courseTypeIsForbidden + ", courseTypeIsDeleted=" + this.courseTypeIsDeleted + ", teacherCourses=" + this.teacherCourses + ", studentCourses=" + this.studentCourses + ")";
        }
    }
}
